<?php $this->_extends('../_layouts/default_layout');?>
<?php $this->_block('contents');?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
}
$(function(){
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true});
	$("#shop_ids").multiselect({height: 260, minWidth: 160});
	$(".revise_flag").mouseover(function(){
		$(this).next().show();
	}).mouseout(function(){
		$(this).next().hide();
	});
	$(".revise_flag_value").mouseover(function(){
		$(this).show();
	}).mouseout(function(){
		$(this).hide();
	});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']:enabled").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$(".revise_flag_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert('请选择邮件');
			return false;
		}
		if (! confirm("确定修改标志？"))
		{
			return false;
		}
		var type = $(this).prev().prev().val();
		var flag = $(this).prev().val();
		window.location.href = "<?=url('Services::EbayMessage/ReviseFlag')?>&ids=" + ids + '&type=' + type + '&flag=' + flag + '&<?=Q::ini('unique_token_name')?>=<?=Helper_BSS_Normal::genToken()?>';
	});
});
</script>
<style type="text/css">
.revise_flag_value {
	position: absolute;
	top: 2px;
	left: 36px;
	width: 57px;
	background-color: #eeeeee;
	z-index: 100;
	display: none;
	border: 1px solid;
}
</style>
<fieldset><legend>查询条件</legend>
<form method="get">
<?include (Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>接收时间</th>
	<td>
		<input type="text" class="datepicker" name="begin_receive_time" value="<?=isset($_GET['begin_receive_time']) ? $_GET['begin_receive_time'] : ''?>" /> To
		<input type="text" class="datepicker" name="end_receive_time" value="<?=isset($_GET['end_receive_time']) ? $_GET['end_receive_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th>店铺</th>
	<td>
		<select name="shop_ids[]" multiple="multiple" id="shop_ids">
			<optgroup label="ebay">
				<?foreach ($shop as $s):?>
				<option value="<?=$s['id']?>" <?if (isset($_GET['shop_ids']) && in_array($s['id'], $_GET['shop_ids'])):?>selected="selected"<?endif;?>><?=$s['name']?></option>
				<?endforeach;?>
			</optgroup>
		</select>
	</td>
</tr>
<tr>
	<th>发送账号</th>
	<td><input type="text" name="sender" value="<?=isset($_GET['sender']) ? $_GET['sender'] : ''?>" /></td>
</tr>
<tr>
	<th>邮件来自</th>
	<td>
		<label><input type="checkbox" name="from[]" value="ebay" <?if (isset($_GET['from']) && in_array('ebay', $_GET['from'])):?>checked="checked"<?endif;?> />ebay</label>
		<label><input type="checkbox" name="from[]" value="member" <?if (isset($_GET['from']) && in_array('member', $_GET['from'])):?>checked="checked"<?endif;?> />member</label>
	</td>
</tr>
<tr>
	<th>读取状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/services_ebay_message_read') as $r):?>
		<label><input type="checkbox" name="read[<?=$r['value']?>]" value="<?=$r['value']?>" <?if (isset($_GET['read']) && array_key_exists($r['value'], $_GET['read'])):?>checked="checked"<?endif;?> /><?=$r['name']?></label>&nbsp;
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>回复状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/services_ebay_message_replied') as $r):?>
		<label><input type="checkbox" name="replied[<?=$r['value']?>]" value="<?=$r['value']?>" <?if (isset($_GET['replied']) && array_key_exists($r['value'], $_GET['replied'])):?>checked="checked"<?endif;?> /><?=$r['name']?></label>&nbsp;
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>标志状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/services_ebay_message_flagged') as $f):?>
		<label><input type="checkbox" name="flagged[<?=$f['value']?>]" value="<?=$f['value']?>" <?=isset($_GET['flagged']) && in_array($f['value'], $_GET['flagged']) ? "checked=checked" : ''?>/><span class="<?=$f['icon_class']?>">&nbsp;&nbsp;&nbsp;&nbsp;</span><?=$f['value'] == 0 ? '未标志' : $f['name']?></label>&nbsp;
		<?endforeach;?>
	</td>
</tr>
<tr>
	<td colspan="2"><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>
<table class="list_table" width="97%" id="list">
<tr>
	<th width="30"></th>
	<th>邮件主题</th>
	<th>发送账号</th>
	<th width="140">接收时间</th>
	<th>接收账号</th>
	<th width="60">操作</th>
</tr>
<?foreach ($message as $m):?>
<tr>
	<td><input type="checkbox" value="<?=$m['id']?>" /></td>
	<td style="text-align: left;">
		<span class="<?=($m['replied'] == 1 ? 'message_replied_icon' : 'message_' . Helper_BSS_Normal::getIniOne('services_ebay_message_read', 'value', $m['read'], 'icon_class'))?>" title="<?=($m['replied'] == 1 ? Helper_BSS_Normal::getIniOne('services_ebay_message_replied', 'value', $m['replied'], 'name') : Helper_BSS_Normal::getIniOne('services_ebay_message_read', 'value', $m['read'], 'name'))?>">&nbsp;</span>
		<?if ($m['flagged']):?><span class="<?=Helper_BSS_Normal::getIniOne('services_ebay_message_flagged', 'value', $m['flagged'], 'icon_class')?>" title="<?=Helper_BSS_Normal::getIniOne('services_ebay_message_flagged', 'value', $m['flagged'], 'name')?>标志">&nbsp;&nbsp;&nbsp;</span><?endif;?>
		<a href="<?=url('Services::EbayMessage/Detail', array('id' => $m['id']))?>" target=_blank><?=$m['subject']?></a>
	</td>
	<td><?=$m['sender']?></td>
	<td><?=$m['receive_time']?></td>
	<td><?=$m['recipient']?></td>
	<td>
		<div style="float: right; position: relative;">
		<a class="revise_flag">标志为&or;</a>
		<ul class="revise_flag_value">
			<?foreach (Q::ini('custom_flag/services_ebay_message_read') as $r):?>
			<li><a href="<?=url('Services::EbayMessage/ReviseFlag', array('type' => 'read', 'flag' => $r['value'], 'ids' => $m['id'], Q::ini('unique_token_name') => Helper_BSS_Normal::genToken()))?>"><span class="<?=$r['icon_class']?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><?=$r['name']?></a></li>
			<?endforeach;?>
			<li><hr /></li>
			<?foreach (Q::ini('custom_flag/services_ebay_message_flagged') as $f):?>
			<li><a href="<?=url('Services::EbayMessage/ReviseFlag', array('type' => 'flagged', 'flag' => $f['value'], 'ids' => $m['id'], Q::ini('unique_token_name') => Helper_BSS_Normal::genToken()))?>"><span class="<?=$f['icon_class']?>">&nbsp;&nbsp;&nbsp;&nbsp;</span><?=$f['name']?></a></li>
			<?endforeach;?>
		</ul>
		</div>
	</td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
	<td><label><input type="checkbox" id="check_all" />全选</label></td>
	<td>标志为：
		<?foreach (Q::ini('custom_flag/services_ebay_message_read') as $r):?>
		<input type="hidden" name="type" value="read" />
		<input type="hidden" name="flag" value="<?=$r['value']?>" />
		<a class="revise_flag_btn"><span class="<?=$r['icon_class']?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><?=$r['name']?></a>
		<?endforeach;?>
		<?foreach (Q::ini('custom_flag/services_ebay_message_flagged') as $f):?>
		<input type="hidden" name="type" value="flagged" />
		<input type="hidden" name="flag" value="<?=$f['value']?>" />
		<a class="revise_flag_btn"><span class="<?=$f['icon_class']?>">&nbsp;&nbsp;&nbsp;&nbsp;</span><?=$f['name']?></a>
		<?endforeach;?>
	</td>
</tr>
</table>
<?php $this->_endblock();?>